return ptr;
}
-xc_dominfo_t * libxl_domain_infolist(struct libxl_ctx *ctx, int *nb_domain)
-{
- int index, first_domain;
- xc_dominfo_t *info;
- int size = 1024;
-
- first_domain = 0;
- index = 0;
- info = (xc_dominfo_t *) calloc(size, sizeof(xc_dominfo_t));
- if (!info) {
- *nb_domain = 0;
- return NULL;
- }
- *nb_domain = xc_domain_getinfo(ctx->xch, first_domain, 1024, info);
- return info;
-}
-
-xc_dominfo_t *libxl_domain_info(struct libxl_ctx *ctx, uint32_t domid)
-{
- xc_dominfo_t *info;
- int rc;
-
- info = (xc_dominfo_t *) calloc(1, sizeof(xc_dominfo_t));
- if (!info) {
- return NULL;
- }
- rc = xc_domain_getinfo(ctx->xch, domid, 1, info);
- if (rc != 1) {
- free(info);
- XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "Failed to get info for domain %u",
- domid);
- return NULL;
- }
- if (info->domid != domid) {
- free(info);
- XL_LOG(ctx, XL_LOG_ERROR, "Failed to get info for domain %u"
- ", seems to not exist anymore", domid);
- return NULL;
- }
-
- return info;
-}
-
int libxl_domain_suspend(struct libxl_ctx *ctx, libxl_domain_suspend_info *info,
uint32_t domid, int fd)
{
return 0;
}
-int libxl_event_get_domain_death_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, xc_dominfo_t *info)
+int libxl_event_get_domain_death_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, xc_domaininfo_t *info)
{
- int nb_domain, i, rc = 0;
- xc_dominfo_t *list = NULL;
+ int rc = 0, ret;
if (event && event->type == DOMAIN_DEATH) {
- list = libxl_domain_infolist(ctx, &nb_domain);
- for (i = 0; i < nb_domain; i++) {
- if (domid == list[i].domid) {
- if (list[i].running || (!list[i].shutdown && !list[i].crashed && !list[i].dying))
+ ret = xc_domain_getinfolist(ctx->xch, domid, 1, info);
+ if (ret == 1 && info->domain == domid) {
+ if (info->flags & XEN_DOMINF_running ||
+ (!(info->flags & XEN_DOMINF_shutdown) && !(info->flags & XEN_DOMINF_dying)))
goto out;
- *info = list[i];
rc = 1;
goto out;
- }
}
- memset(info, 0x00, sizeof(xc_dominfo_t));
+ memset(info, 0, sizeof(xc_dominfo_t));
rc = 1;
goto out;
}
out:
- free(list);
return rc;
}
int libxl_free_event(libxl_event *event);
int libxl_free_waiter(libxl_waiter *waiter);
-int libxl_event_get_domain_death_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, xc_dominfo_t *info);
+int libxl_event_get_domain_death_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, xc_domaininfo_t *info);
int libxl_event_get_disk_eject_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, libxl_device_disk *disk);
int libxl_console_attach(struct libxl_ctx *ctx, uint32_t domid, int cons_num);
struct libxl_dominfo * libxl_domain_list(struct libxl_ctx *ctx, int *nb_domain);
-xc_dominfo_t * libxl_domain_infolist(struct libxl_ctx *ctx, int *nb_domain);
-xc_dominfo_t * libxl_domain_info(struct libxl_ctx *ctx, uint32_t domid);
typedef struct libxl_device_model_starting libxl_device_model_starting;
int libxl_create_device_model(struct libxl_ctx *ctx,
}
XL_LOG(si->ctx, XL_LOG_DEBUG, "wait for the guest to suspend");
while (!strcmp(state, "suspend") && watchdog > 0) {
- int nb_domain, i;
- xc_dominfo_t *list = NULL;
+ xc_domaininfo_t info;
+
usleep(100000);
- list = libxl_domain_infolist(si->ctx, &nb_domain);
- for (i = 0; i < nb_domain; i++) {
- if (si->domid == list[i].domid) {
- if (list[i].shutdown != 0 && list[i].shutdown_reason == SHUTDOWN_suspend) {
- free(list);
- return 1;
- }
- }
+ ret = xc_domain_getinfolist(si->ctx->xch, si->domid, 1, &info);
+ if (ret == 1 && info.domain == si->domid && info.flags & XEN_DOMINF_shutdown) {
+ int shutdown_reason;
+
+ shutdown_reason = (info.flags >> XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask;
+ if (shutdown_reason == SHUTDOWN_suspend)
+ return 1;
}
- free(list);
state = libxl_xs_read(si->ctx, XBT_NULL, path);
watchdog--;
}
while (1) {
int ret;
fd_set rfds;
- xc_dominfo_t info;
+ xc_domaininfo_t info;
libxl_event event;
libxl_device_disk disk;
memset(&info, 0x00, sizeof(xc_dominfo_t));
case DOMAIN_DEATH:
if (libxl_event_get_domain_death_info(&ctx, domid, &event, &info)) {
LOG("Domain %d is dead", domid);
- if (info.crashed || info.dying || (info.shutdown && (info.shutdown_reason != SHUTDOWN_suspend))) {
+ if (info.flags & XEN_DOMINF_dying || (info.flags & XEN_DOMINF_shutdown && (((info.flags >> XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask) != SHUTDOWN_suspend))) {
LOG("Domain %d needs to be clean: destroying the domain", domid);
libxl_domain_destroy(&ctx, domid, 0);
- if (info.shutdown && (info.shutdown_reason == SHUTDOWN_reboot)) {
+ if (info.flags & XEN_DOMINF_shutdown &&
+ (((info.flags >> XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask) == SHUTDOWN_reboot)) {
libxl_free_waiter(w1);
libxl_free_waiter(w2);
free(w1);
void list_domains(void)
{
struct libxl_ctx ctx;
- xc_dominfo_t *info;
+ struct libxl_dominfo *info;
int nb_domain, i;
libxl_ctx_init(&ctx);
libxl_ctx_set_log(&ctx, log_callback, NULL);
- info = libxl_domain_infolist(&ctx, &nb_domain);
+ info = libxl_domain_list(&ctx, &nb_domain);
if (info < 0) {
fprintf(stderr, "libxl_domain_infolist failed.\n");
exit(1);
}
- printf("Name ID Mem VCPUs\tState\tTime(s)\n");
+ printf("Name ID \tState\n");
for (i = 0; i < nb_domain; i++) {
- printf("%-40s %5d %5lu %5d %c%c%c%c%c%c %8.1f\n",
+ printf("%-40s %5d %c%c%c\n",
libxl_domid_to_name(&ctx, info[i].domid),
info[i].domid,
- info[i].nr_pages * XC_PAGE_SIZE/(1024*1024),
- info[i].nr_online_vcpus,
info[i].running ? 'r' : '-',
- info[i].blocked ? 'b' : '-',
info[i].paused ? 'p' : '-',
- info[i].shutdown ? 's' : '-',
- info[i].crashed ? 'c' : '-',
- info[i].dying ? 'd' : '-',
- ((float)info[i].cpu_time / 1e9));
+ info[i].dying ? 'd' : '-');
}
free(info);
}